/*
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *    2010 year
 *    Author: Michael Khromov aka MikeDM (Mike D'Morto)
 *    E-Mail: mikedmorto@gmail.com
 */

#include "mainwin.h"
#include "ui_mainwin.h"
#include <QDebug>
#include <QKeyEvent>

MainWin::MainWin(QList<TsIfaceWrkPlugin *> *wrklist, QWidget *parent) :
        QDialog(parent),
        ui(new Ui::MainWin)
    {
        ui->setupUi(this);
        // добавляем кнопку минимизации окна.
        this->setWindowFlags(Qt::WindowMinMaxButtonsHint);
        this->mwrklist=wrklist;
        this->setWindowTitle(APP_NAME+tr(" - main window"));
        // заполняем списог
        QListWidgetItem * it;
        for(int i = 0 ; i < this->mwrklist->size() ; i++){
        it = new QListWidgetItem(this->mwrklist->at(i)->getName());
        this->ui->lw_wkr->addItem(it);
        }

        this->ui->lw_wkr->installEventFilter(this);
    }

void MainWin::slotRow(QModelIndex row){

    //this->setVisible(false);
    this->startPlugin();
    //this->setVisible(true);
}

void MainWin::startPlugin(){
    this->setVisible(false);
    this->mwrklist->at(this->ui->lw_wkr->currentRow())->qstart();
    this->setVisible(true);
}

bool MainWin::eventFilter(QObject *obj, QEvent *event){
    if (event->type() == QEvent::KeyPress) {
             QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
             if( keyEvent->key() == Qt::Key_Return){
                 this->startPlugin();
             }
             return false;
         } else {
             // standard event processing
             return QObject::eventFilter(obj, event);
         }
}

MainWin::~MainWin()
{
    delete ui;
}
